import 'package:flui/flui.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:fzcgx_app/common/adapter_utils.dart';
import 'package:fzcgx_app/network/http.dart';

import 'package:fzcgx_app/ui/my/factory/page/factory_page.dart';
import 'package:fzcgx_app/ui/my/worker/page/worker_page.dart';
import 'package:fzcgx_app/ui/widget/custom_appbar_widget.dart';
import 'package:nav_router/nav_router.dart';

class SelectTypePage extends StatefulWidget {
  SelectTypePage({Key key}) : super(key: key);

  @override
  _SelectTypePageState createState() => _SelectTypePageState();
}

class _SelectTypePageState extends State<SelectTypePage> {
  TextEditingController _phoneController = TextEditingController();
  bool isReady = false;
  int selectIndex;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppbar(),
      body: SafeArea(
          child: SingleChildScrollView(
              child: Container(
        margin: EdgeInsets.symmetric(horizontal: AdapterUtils.getWidth(15)),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Text(
              '服装产业链上下游注册',
              style: TextStyle(
                fontSize: AdapterUtils.getSp(26),
                color: Color(0xff141F33),
                fontWeight: FontWeight.bold,
              ),
            ),
            SizedBox(
              height: AdapterUtils.getHeight(2),
            ),
            Text(
              '选择身份',
              style: TextStyle(
                fontSize: AdapterUtils.getSp(14),
                color: Color(0xff666C73),
                fontWeight: FontWeight.w500,
              ),
            ),
            SizedBox(
              height: AdapterUtils.getHeight(62),
            ),
            InkWell(
              onTap: () {
                if (mounted) {
                  setState(() {
                    selectIndex = 1;
                    if (_phoneController.text.isNotEmpty && selectIndex > 0) {
                      isReady = true;
                    } else {
                      isReady = false;
                    }
                  });
                }
              },
              child: Container(
                height: AdapterUtils.getHeight(50),
                decoration: BoxDecoration(
                    border: Border.all(
                        color: selectIndex == 1
                            ? Color(0xff15A1FF)
                            : Color(0xffDFE0E3),
                        width: 1),
                    borderRadius: BorderRadius.all(Radius.circular(4))),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: <Widget>[
                    Expanded(
                      child: Container(),
                    ),
                    Expanded(
                      child: Container(
                        child: Row(
                          children: <Widget>[
                            Image.asset('assets/images/company.png'),
                            SizedBox(
                              width: AdapterUtils.getWidth(11),
                            ),
                            Text(
                              '我是公司',
                              style: TextStyle(
                                fontSize: AdapterUtils.getSp(16),
                                color: Color(0xff60666E),
                                fontWeight: FontWeight.w500,
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                    Expanded(
                        child: Container(
                      alignment: Alignment.centerRight,
                      margin: EdgeInsets.only(right: AdapterUtils.getWidth(15)),
                      child: Offstage(
                        offstage: selectIndex == 1 ? false : true,
                        child: Image.asset('assets/images/select.png'),
                      ),
                    ))
                  ],
                ),
              ),
            ),
            SizedBox(
              height: AdapterUtils.getHeight(12),
            ),
            Center(
              child: Text(
                '自己没有工厂，全部外发生产',
                style: TextStyle(
                  fontSize: AdapterUtils.getSp(12),
                  color: Color(0xff8A9199),
                  fontWeight: FontWeight.w500,
                ),
              ),
            ),
            SizedBox(
              height: AdapterUtils.getHeight(22),
            ),
            InkWell(
              onTap: () {
                if (mounted) {
                  setState(() {
                    selectIndex = 2;
                    if (_phoneController.text.isNotEmpty && selectIndex > 0) {
                      isReady = true;
                    } else {
                      isReady = false;
                    }
                  });
                }
              },
              child: Container(
                height: AdapterUtils.getHeight(50),
                decoration: BoxDecoration(
                    border: Border.all(
                        color: selectIndex == 2
                            ? Color(0xff15A1FF)
                            : Color(0xffDFE0E3),
                        width: 1),
                    borderRadius: BorderRadius.all(Radius.circular(4))),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Expanded(child: Container()),
                    Expanded(
                        child: Container(
                      child: Row(
                        children: <Widget>[
                          Image.asset('assets/images/factory.png'),
                          SizedBox(
                            width: AdapterUtils.getWidth(11),
                          ),
                          Text(
                            '我是工厂',
                            style: TextStyle(
                              fontSize: AdapterUtils.getSp(16),
                              color: Color(0xff60666E),
                              fontWeight: FontWeight.w500,
                            ),
                          ),
                        ],
                      ),
                    )),
                    Expanded(
                        child: Container(
                      alignment: Alignment.centerRight,
                      margin: EdgeInsets.only(right: AdapterUtils.getWidth(15)),
                      child: Offstage(
                        offstage: selectIndex == 2 ? false : true,
                        child: Image.asset('assets/images/select.png'),
                      ),
                    ))
                  ],
                ),
              ),
            ),
            SizedBox(
              height: AdapterUtils.getHeight(12),
            ),
            Center(
              child: Text(
                '纯加工厂，没有自己品牌',
                style: TextStyle(
                  fontSize: AdapterUtils.getSp(12),
                  color: Color(0xff8A9199),
                  fontWeight: FontWeight.w500,
                ),
              ),
            ),
            SizedBox(
              height: AdapterUtils.getHeight(22),
            ),
            InkWell(
              onTap: () {
                if (mounted) {
                  setState(() {
                    selectIndex = 3;
                    if (_phoneController.text.isNotEmpty && selectIndex > 0) {
                      isReady = true;
                    } else {
                      isReady = false;
                    }
                  });
                }
              },
              child: Container(
                height: AdapterUtils.getHeight(50),
                decoration: BoxDecoration(
                    border: Border.all(
                        color: selectIndex == 3
                            ? Color(0xff15A1FF)
                            : Color(0xffDFE0E3),
                        width: 1),
                    borderRadius: BorderRadius.all(Radius.circular(4))),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Expanded(child: Container()),
                    Expanded(
                        child: Container(
                      child: Row(
                        children: <Widget>[
                          Image.asset('assets/images/worker.png'),
                          SizedBox(
                            width: AdapterUtils.getWidth(11),
                          ),
                          Text(
                            '我要应聘',
                            style: TextStyle(
                              fontSize: AdapterUtils.getSp(16),
                              color: Color(0xff60666E),
                              fontWeight: FontWeight.w500,
                            ),
                          ),
                        ],
                      ),
                    )),
                    Expanded(
                        child: Container(
                      alignment: Alignment.centerRight,
                      margin: EdgeInsets.only(right: AdapterUtils.getWidth(15)),
                      child: Offstage(
                        offstage: selectIndex == 3 ? false : true,
                        child: Image.asset('assets/images/select.png'),
                      ),
                    ))
                  ],
                ),
              ),
            ),
            SizedBox(
              height: AdapterUtils.getHeight(12),
            ),
            Center(
              child: Text(
                '服装产业上下游员工或者找工作',
                style: TextStyle(
                  fontSize: AdapterUtils.getSp(12),
                  color: Color(0xff8A9199),
                  fontWeight: FontWeight.w500,
                ),
              ),
            ),
            SizedBox(
              height: AdapterUtils.getHeight(60),
            ),
            Container(
              height: AdapterUtils.getHeight(60),
              decoration: BoxDecoration(
                border: Border.all(color: Color(0xffDFE0E3), width: 1),
                borderRadius: BorderRadius.all(Radius.circular(4)),
              ),
              child: Row(
              
                children: <Widget>[
                  SizedBox(
                    width: AdapterUtils.getWidth(14),
                  ),
                  Text(
                    '+86',
                    style: TextStyle(
                        fontWeight: FontWeight.bold,
                        color: Color(0xff1F2329),
                        fontSize: AdapterUtils.getSp(16)),
                  ),
                  Icon(
                    Icons.arrow_drop_down,
                    color: Color(0xff646A73),
                  ),
                  SizedBox(
                    width: AdapterUtils.getWidth(15),
                  ),
                  Container(
                    height: AdapterUtils.getHeight(19),
                    width: 2,
                    color: Color(0xffDDE0E3),
                  ),
                  SizedBox(
                    width: AdapterUtils.getWidth(15),
                  ),
                  Expanded(
                    child: TextField(
                      controller: _phoneController,
                      keyboardType: TextInputType.phone,
                      onChanged: (value) {
                        if (_phoneController.text.isNotEmpty &&
                            selectIndex > 0) {
                          isReady = true;
                        } else {
                          isReady = false;
                        }
                        if (mounted) {
                          setState(() {});
                        }
                      },
                      style: TextStyle(
                        fontSize: AdapterUtils.getSp(16),
                        color: Color(0xff000000),
                        fontWeight: FontWeight.w500,
                      ),
                      decoration: InputDecoration(
                          hintText: '介绍人手机号码',
                          border: InputBorder.none,
                       
                          hintStyle: TextStyle(
                            fontSize: AdapterUtils.getSp(16),
                            color: Color(0xff8F959E),
                            fontWeight: FontWeight.w500,
                          )),
                    ),
                  ),
                ],
              ),
            ),
            SizedBox(
              height: AdapterUtils.getHeight(62),
            ),
            Center(
              child: RichText(
                text: TextSpan(children: <InlineSpan>[
                  TextSpan(
                    text: '点击下一步代表你已阅读同意',
                    style: TextStyle(
                      fontSize: AdapterUtils.getSp(12),
                      color: Color(0xff8A9199),
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                  TextSpan(
                    text: '服务协议',
                    style: TextStyle(
                      fontSize: AdapterUtils.getSp(12),
                      color: Color(0xff15A1FF),
                      fontWeight: FontWeight.w500,
                    ),
                    recognizer: TapGestureRecognizer()..onTap = () {},
                  ),
                  TextSpan(
                    text: '和',
                    style: TextStyle(
                      fontSize: AdapterUtils.getSp(12),
                      color: Color(0xff8A9199),
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                  TextSpan(
                    text: '隐私政策',
                    style: TextStyle(
                      fontSize: AdapterUtils.getSp(12),
                      color: Color(0xff15A1FF),
                      fontWeight: FontWeight.w500,
                    ),
                    recognizer: TapGestureRecognizer()..onTap = () {},
                  ),
                ]),
              ),
            ),
            SizedBox(
              height: AdapterUtils.getHeight(16),
            ),
            Container(
                width: AdapterUtils.screenWidth(),
                height: AdapterUtils.getHeight(50),
                child: FlatButton(
                    onPressed: isReady
                        ? () {
                            var dismiss = FLToast.loading(text: '正在加载中...');
                            Http.instance
                                .post('app/call/setUserTypeIntroducer', {
                              'type': selectIndex == 1
                                  ? '101'
                                  : selectIndex == 2
                                      ? '102'
                                      : selectIndex == 3 ? '103' : ''
                            }, onSuccess: (data) {
                              dismiss();
                              selectIndex == 1 ? routePush(FactoryPage()) :selectIndex == 2? routePush(FactoryPage()):routePush(WorkerPage()) ;
                            }, onError: (error) {
                              dismiss();
                            }, onFail: (fail) {
                               dismiss();
                            });
                          }
                        : null,
                    disabledColor: Color(0xff15A1FF).withAlpha(80),
                    color: Color(0xff15A1FF),
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.all(Radius.circular(4)),
                    ),
                    child: Text(
                      '下一步',
                      style: TextStyle(
                        fontSize: AdapterUtils.getSp(16),
                        color: Colors.white,
                        fontWeight: FontWeight.w500,
                      ),
                    ))),
            SizedBox(
              height: AdapterUtils.getHeight(16),
            ),
          ],
        ),
      ))),
    );
  }
}
